package te2;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import test.Student;

/**
*@author created by zhanxianbo
*@date 2017��3��31��--����2:52:15
*/
public class tostring {

	private static final Object Student = null;


	public static <K, V> void main(String[] args) {
		
		Student stu=new Student();
		stu.setAge(20);
		stu.setName("132");
		
		Student stu1=new Student();
		stu1.setAge(30);
		stu1.setName("1324654");
		
		Student stu2=new Student();
		stu2.setAge(40);
		stu2.setName("11111111111");
		
		List<Student> list=new ArrayList<Student>();
		list.add(stu);
		list.add(stu1);
		list.add(stu2);
		
		
		
	/*	Gson  gson = new Gson();
		String gs = gson.toJson(stu);
		System.out.println(gs);*/
		
		JSONArray jArray=new JSONArray();
		
		for (Student lists:list) {
			JSONObject object=new JSONObject();
			object.put("0", lists.getAge());
			object.put("1", lists.getName());
				jArray.add(object);
		}
		
		
		/*for (int i = 0; i < jArray.size(); i++) {
			
		JSONObject  object=(JSONObject) jArray.get(i);
		for (int j = 0; j < 2; j++) {
			System.out.println(object.get(""+j+""));
		}*/
		
		/*for (int j = 0; j < 3; j++) {
			System.out.println(object.get(""+ j +""));
		}*/
		
				
	//	String jsonstring = JSON.toJSONString(list);
		//toarray(jsonstring);
		
		/*System.out.println(jsonstring+"jsonstring");
		JSONArray array=new JSONArray();*/
		
		//array.toArray();
	
		
		
		//System.out.println(jsonstring+"jsonstring");
		/*Student s=new Student();
		s.setId("1");
		s.setAge(23);
		s.setName("123");
		
		List<Student> lists=new ArrayList<Student>();
		lists.add(s);
		
		String li=JSON.toJSONString(lists);
		fan(li,s);*/
		
		/*Gson gson = new Gson();  
		List<Student> persons = gson.fromJson(jsonstring, new TypeToken<List<Student>>(){}.getType());
		System.out.println(persons+"persons");
		JSONArray jArray=new JSONArray();
		
		for (Student lists:persons) {
			JSONObject object=new JSONObject();
			object.put("id", lists.getId());
			object.put("age", lists.getAge());
			jArray.add(object);
		}*/
	 
	
	
	/*public static   void toarray(String  jsonstring){
		  
        List<Student> lis = JSONObject.parseArray(jsonstring, Student.class);  
        JSONArray jArray=new JSONArray();
		
		for (Student lists:lis) {
			JSONObject object=new JSONObject();
			object.put("name", lists.getName());
			object.put("age", lists.getAge());
			jArray.add(object);
		}
	System.out.println(jArray.toString());
	
	}*/
	
	
	/*public static <T, t> void fan(String  jsonstring,T  t){
		
		if(jsonstring != null && t!= null){
			 	List<t> lis =  (List<t>) JSONObject.parseArray(jsonstring,t.getClass());  
		        JSONArray jArray=new JSONArray();
				
				for (t lists:lis) {
					JSONObject object=new JSONObject();
					object.put("id", ((model.Student) lists).getId());
					object.put("targetType", ((Object) lists).getTargetType());
					object.put("targetImg", ((model.Student) lists).getTargetImg());
					object.put("targetName", ((model.Student) lists).getTargetName())
					jArray.add(object);
				}
				
				System.out.println(jArray);
		}
	
	}*/
	
	}

	}
